package com.itheima.app.controller.omsController;

import com.itheima.app.manager.omsManager.OmsOrderReturnReasonManager;
import com.itheima.commons.R;
import com.itheima.domain.db.oms.OmsOrderReturnReason;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 退货原因
 */
@CrossOrigin    //跨域
@RestController
public class OmsOrderReturnReasonController {
    @Autowired
    OmsOrderReturnReasonManager omsOrderReturnReasonManager;

    /**
     * 分页查询退货原因
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/returnReason/list")
    public R pageReturnReason(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return omsOrderReturnReasonManager.pageReturnReason(pageNum, pageSize);
    }

    /**
     * 添加退货原因
     *
     * @param omsOrderReturnReason
     * @return
     */
    @PostMapping("/returnReason/create")
    public R addReturnReason(@RequestBody OmsOrderReturnReason omsOrderReturnReason) {
        omsOrderReturnReasonManager.addReturnReason(omsOrderReturnReason);
        return R.ok(null);
    }

    /**
     * 批量删除退货原因
     *
     * @param ids
     * @return
     */
    @PostMapping("/returnReason/delete")
    public R deleteReturnReason(Integer[] ids) {
        omsOrderReturnReasonManager.deleteReturnReason(ids);
        return R.ok(null);
    }

    /**
     * 修改退货原因启用状态
     * 根据id修改,非ids数组
     *
     * @param ids
     * @return
     */
    @PostMapping("/returnReason/update/status")
    public R updateStatus(Integer ids, Integer status) {
        omsOrderReturnReasonManager.updateStatus(ids, status);
        return R.ok(null);
    }

    /**
     * 获取单个退货原因详情信息
     *
     * @param id
     * @return
     */
    @GetMapping("/returnReason/{id}")
    public R getInfoById(@PathVariable Integer id) {
        return omsOrderReturnReasonManager.getInfoById(id);
    }

    /**
     * 修改退货原因
     *
     * @param id
     * @param omsOrderReturnReason
     * @return
     */
    @PostMapping("/returnReason/update/{id}")
    public R updateInfo(@PathVariable Integer id, @RequestBody OmsOrderReturnReason omsOrderReturnReason) {
        omsOrderReturnReasonManager.updateInfo(id, omsOrderReturnReason);
        return R.ok(null);
    }
}
